﻿@namespace MudBlazor

@inherits MudComponentBase

<MudElement HtmlTag="ul" Class="@Classname" Style="@Style" Tag="@Tag" UserAttributes="@UserAttributes">
    @if (ShowFirstButton)
    {
        <li class="@ItemClassname">
            <MudIconButton Icon="@FirstIcon" Size="@Size" Variant="@Variant" Disabled="@(Selected == 1 || Disabled)" OnClick="@(() => OnClickControlButton(Page.First))" aria-label="First page"></MudIconButton>
        </li>
    }
    @if (ShowPreviousButton)
    {
        <li class="@ItemClassname">
            <MudIconButton Icon="@BeforeIcon" Size="@Size" Variant="@Variant" Disabled="@(Selected == 1 || Disabled)" OnClick="@(() => OnClickControlButton(Page.Previous))" aria-label="Previous page"></MudIconButton>
        </li>
    }
    @foreach (var state in GeneratePagination())
    {
        var currentPage = state;
        if (currentPage == -1)
        {
            <li class="@ItemClassname">
                <MudText disabled="@Disabled">...</MudText>
            </li>
        }
        else if (currentPage == Selected)
        {
            <li class="@SelectedItemClassname">
                <MudButton Variant="@(Variant == Variant.Outlined ? Variant.Outlined : Variant.Filled)" Size="@Size" DisableRipple="true" Disabled="@Disabled" Color="@Color" aria-current="page" aria-label="@($"Current page {currentPage}")">@currentPage</MudButton>
            </li>
        }
        else {
            <li class="@ItemClassname">
                <MudButton OnClick="@(() => Selected = currentPage)" Variant="@Variant" Size="@Size" DisableRipple="true" Disabled="@Disabled" aria-label="@($"Page {currentPage}")">@currentPage</MudButton>
            </li>
        }
    }
    @if (ShowNextButton)
    {
        <li class="@ItemClassname">
            <MudIconButton Icon="@NextIcon" Variant="@Variant" Size="@Size" Disabled="@(Selected == Count || Disabled)" OnClick="@(() => OnClickControlButton(Page.Next))" aria-label="Next page"></MudIconButton>
        </li>
    }
    @if (ShowLastButton)
    {
        <li class="@ItemClassname">
            <MudIconButton Icon="@LastIcon" Variant="@Variant" Size="@Size" Disabled="@(Selected == Count || Disabled)" OnClick="@(() => OnClickControlButton(Page.Last))" aria-label="Last page"></MudIconButton>
        </li>
    }
</MudElement>